package com.fare.taluo.fetl.domain.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.fare.taluo.fetl.domain.base.EntityFetlHibernateRepository;
import com.fare.taluo.fetl.domain.entity.FreightMonitorCabinsEntity;
import com.fare.taluo.fetl.domain.entity.FreightMontiorEntity;
import com.fare.taluo.fetl.domain.repository.IFreightMonitorCabinRepository;
import com.fare.taluo.util.StringAndDateAndFileUtil;
@Repository
public class IFreightMonitorCabinRepositoryImpl extends EntityFetlHibernateRepository implements IFreightMonitorCabinRepository{

	@Override
	public List<FreightMonitorCabinsEntity> findCabinEntityByFreightMonitor(String id) {
		List<Object> params = new ArrayList<Object>();
		String hql = "from com.fare.taluo.fetl.domain.entity.FreightMonitorCabinsEntity entity where  1=1 ";
		if(StringAndDateAndFileUtil.checkString(id)){
			hql += " and entity.monitorId= ?";
			params.add(id);
		}
		Session session =getSessionFactory1().openSession();
		//Session session  =	super.getHibernateTemplate1().getSessionFactory().openSession();
		List<FreightMonitorCabinsEntity> list = null;
		try {
			Query query = session.createQuery(hql);
			for (int i = 0; i < params.size(); i++) {
			query = query.setParameter(i, params.get(i));
			}
			 list = query.list();
		} catch (Exception e) {
			e.printStackTrace();	
		}finally{
			session.close();
		}
		
		return list;
	}
	
}
